﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Data.SqlClient;

namespace WinForm
{
    public partial class Login : Form
    {
        public Login()
        {
            InitializeComponent();
        }

        private void btnLogin_Click(object sender, EventArgs e)
        {
            if (txtUserName.Text.Trim() == "" || txtPassword.Text.Trim() == "")
            {
                MessageBox.Show("用户名或密码不能为空。");
                txtUserName.Focus();
                return;
            }
            BLL.User user = new BLL.User();
            try {
                if (user.Login(txtUserName.Text.Trim(), txtPassword.Text)) {
                    UserHelper.username = txtUserName.Text.Trim();
                    UserHelper.password = txtPassword.Text;
                    this.Hide();
                    Main f = new Main();
                    f.Show();
                }
                else {
                    MessageBox.Show("用户名或密码错误，请重新输入。", "错误提示",MessageBoxButtons.OK,MessageBoxIcon.Error);
                    txtUserName.Focus();
                    txtUserName.SelectAll();
                }
            }catch(Exception ex) {
                MessageBox.Show(ex.Message);
            }
        }

        private void btnCancel_Click(object sender, EventArgs e)
        {
            this.Close();
        }

        private void Login_Load(object sender, EventArgs e)
        {

        }
    }
}
